package com.example.experiment4.service;

import com.example.experiment4.domain.Person;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class ReadFolder {
//"D:\\code\\集成测试\\integration-test\\Experiment4\\src\\文件整理" +
//                "\\表"
    public List<String> getFolderFileList(String pathname) {
        List<String> flist = new ArrayList<>();
        try{
            System.out.println("文件有如下：");
            File file = new File(pathname);
            //1)如果这个路径是一个文件夹
            if (file.isDirectory()) {
                //2)获取文件夹下的
                File[] files = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isDirectory()) {
                        System.out.println("文件夹:" + files[i].getPath());
                    } else {
                        flist.add(files[i].getPath());
                    }
                }
            } else {
                //这是一个文件
                flist.add(file.getPath());
            }
            return flist;
        }catch (Exception e){
            System.out.println("读取文件夹异常！");
            return null;
        }
    }
}
